<?php
namespace app\back\controller;
use think\Controller;
use think\Request;
use think\Db;
use think\Session;
class Index extends Common
{
	
    public function index()
    {	
       $user_name=Session::get('username');
        
        return $this->fetch('Index/index');
    }
    
    public function left()
    {	
        $module_id = input('module');
        if(empty($module_id)){
            $data = Db::name('module')->where('title','like','%系统%')->find();
            $list = Db::name('module')->where("parent_id=".$data['module_id'])->order('module_id')->select();
            // $this->assign("data",$data);
            $data = list_to_tree($list, 'module_id', 'parent_id',$child = '_child', $data['module_id']);
            $data_r =   Db::name('module')->order('module_id')->select();     
             foreach ($data as $key => $value) {
                foreach ($data_r as $key_r => $value_r) {
                    if($value["module_id"] == $value_r["parent_id"]){
                        $data[$key]["_child"][] = $value_r;
                    }
                }
             }
            $this->assign("cat",$data);
            return $this->fetch();
        }else{
            //获取二级菜单
            $list = Db::name('module')->where("parent_id=".$module_id)->order('module_id')->select();
            // print_r($list);
            $data = list_to_tree($list, 'module_id', 'parent_id',$child = '_child', $module_id);
             //print_r($data);die;   
             $data_r =   Db::name('module')->order('module_id')->select();     
             foreach ($data as $key => $value) {
                foreach ($data_r as $key_r => $value_r) {
                    if($value["module_id"] == $value_r["parent_id"]){
                        $data[$key]["_child"][] = $value_r;
                    }
                }
             }
            //print_r($data);exit;
            $this->assign("cat",$data);
            // $this->assign("data",$data);
            return $this->fetch();
        }
    }
    public function right()
    {	
        //待审核的服务商 
        $server = Db::name('member')->where(['servicer'=>1,'is_pass'=>0])->count();
        //待审核的施工队
        $team = Db::name('member')->where(['form'=>3,'is_pass'=>0])->count();
        //待审核的设计师
        $dersigner = Db::name('member')->where(['form'=>2,'is_pass'=>0])->count();
        //待审核的案例
        $case = Db::name('case')->where('ispassd',0)->count();
        //待审核的问题
        $question = Db::name('ask')->where('status',0)->count(); 
        //待审核答案
        $answer = Db::name('answer')->where('states',0)->count();
        //预约设计师
        $book_dersigner = Db::name('book')->where('book_form',2)->whereTime('book_time', 'today')->count();
        //预约施工队
        $book_team = Db::name('book')->where('book_form',3)->whereTime('book_time', 'today')->count();
        //预约园丁
        $book_gardener = Db::name('book')->where('book_form',4)->whereTime('book_time', 'today')->count();
        //案例评论
        $case_comment = Db::name('case_comment')->where('is_passed',0)->count();
        //获取版本号
        $sysinfo  = array(
            'max_upload' => ini_get("file_uploads") ? ini_get("upload_max_filesize") : "Disabled", //最大上传
            'max_ex_time' => ini_get("max_execution_time")."秒", //脚本最大执行时间
            'memory_limit' => ini_get('memory_limit'),//最大占用内存
            );
        //获取mysql版本号
        $mysql= Db::name('tp5')->query("select VERSION() as version");
        $mysql=$mysql[0]['version'];
        $mysql=empty($mysql)?L('UNKNOWN'):$mysql;
        $this->assign('server',$server);
        $this->assign('team',$team);
        $this->assign('dersigner',$dersigner);
        $this->assign('case',$case);
        $this->assign('question',$question);
        $this->assign('answer',$answer);
        $this->assign('book_dersigner',$book_dersigner);
        $this->assign('book_team',$book_team);
        $this->assign('book_gardener',$book_gardener);
        $this->assign('sysinfo',$sysinfo);
        $this->assign('mysql',$mysql);
        $this->assign('case_comment',$case_comment);
        $this->assign('answer',$answer);
        return $this->fetch();
    }
    public function top()
    {   
        $data = Db::name('module')->where("module='top'")->select();
        $this->assign("data",$data);
        return $this->fetch();
    }
    public function middle()
    {   
        return $this->fetch();
    }
    //修改密码
    public function modifypasswd(){
        return $this->fetch();
    }
	
}
